import { APP_INITIALIZER, NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { NZ_I18N, zh_CN } from "ng-zorro-antd/i18n";
import { HashLocationStrategy, LocationStrategy, registerLocaleData } from "@angular/common";
import zh from "@angular/common/locales/zh";
import { HttpClientModule } from "@angular/common/http";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { SharedModule } from "./share/shared.module";
import { SetupService } from "./services/setup.service";
import { ThemeSkinService } from "./services/theme-skin.service";
import { EmptyComponent } from "./empty.component";

registerLocaleData(zh);

// 初始化服务
const APPINIT_PROVIDES = [
  SetupService,
  {
    provide: APP_INITIALIZER,
    useFactory: (setupService: SetupService) => () => {
      return setupService.load();
    },
    deps: [SetupService],
    multi: true
  },
  {
    provide: APP_INITIALIZER,
    useFactory: (themeService: ThemeSkinService) => () => {
      return themeService.loadTheme();
    },
    deps: [ThemeSkinService],
    multi: true
  }
];

@NgModule({
  declarations: [AppComponent, EmptyComponent],
  imports: [BrowserModule, AppRoutingModule, HttpClientModule, BrowserAnimationsModule, SharedModule],
  providers: [
    { provide: NZ_I18N, useValue: zh_CN },
    { provide: LocationStrategy, useClass: HashLocationStrategy },
    ...APPINIT_PROVIDES
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}
